package com.java.zhuiyun.api.pictureidiomlevel.service.impl;

import com.java.zhuiyun.api.pictureidiomlevel.dao.PictureIdiomLevelMapper;
import com.java.zhuiyun.api.pictureidiomlevel.entity.PictureIdiomLevel;
import com.java.zhuiyun.api.pictureidiomlevel.service.PictureIdiomLevelService;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.util.pageUtil.MybatisPageHelper;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import com.java.zhuiyun.util.pageUtil.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName PrictrueIdiomLevelServiceImpl
 * @Description TODO
 * @Author MJL
 * @Date 2023/9/14 8:35
 **/
@Service
public class PictureIdiomLevelServiceImpl implements PictureIdiomLevelService {
    @Resource
    PictureIdiomLevelMapper pictureIdiomLevelMapper;
    /**
    * @Author MJL
    * @Description todo 添加关卡
    * @Date 2023/9/14 9:12
    * @Return  * @param null
    */
    @Override
    public CommonResult addPictureIdiomLevel(PictureIdiomLevel pictureIdiomLevel) {
//        pictureIdiomLevel.setNumMax(9);
        pictureIdiomLevel.setIsAllocation(1);
        // 添加时间
        pictureIdiomLevel.setCreateTime(new Date());
        // 删除标识
        pictureIdiomLevel.setDelFlag(0);
        int i = pictureIdiomLevelMapper.addPictureIdiomLevel(pictureIdiomLevel);
        if (i>0) {
            return CommonResult.ok("操作成功");
        }else {
            return CommonResult.error("操作失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 查询看图猜成语所有关卡
    * @Date 2023/9/14 11:42
    * @Return  * @param null
    */
    @Override
    public PageResult queryPictureIdiomLevel(PictureIdiomLevel pictureIdiomLevel, PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        PageResult pageResult = MybatisPageHelper.getPageResult(pictureIdiomLevelMapper.queryPictureIdiomLevel(pictureIdiomLevel));
        return pageResult;
    }

    @Override
    public PageResult queryLevelIdiom(Integer id, PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        PageResult pageResult = MybatisPageHelper.getPageResult(pictureIdiomLevelMapper.queryLevelIdiom(id));
        return pageResult;
    }
    /**
    * @Author MJL
    * @Description todo 将关卡下架
    * @Date 2023/10/16 20:28
    * @Return  * @param null
    */
    @Override
    public CommonResult bannedLevel(Integer id) {
        Integer i = pictureIdiomLevelMapper.bannedLevel(id);
        if (i > 0) {
            return CommonResult.ok("操作成功");
        } else {
            return CommonResult.error("操作失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 将关卡上架
    * @Date 2023/10/16 20:33
    * @Return  * @param null
    */
    @Override
    public CommonResult enableLevel(Integer id) {
        Integer i = pictureIdiomLevelMapper.enableLevel(id);
        if (i > 0) {
            return CommonResult.ok("操作成功");
        } else {
            return CommonResult.error("操作失败");
        }
    }
}
